<?php
namespace Home\Controller;
use Think\Controller;
class TestController extends Controller {
	public function w1(){
		$this->display();
	}
	public function newW1(){
		$wdb = M('writing');
		$data['article'] = I('article');
		$data['q'] = 1;
		if ($_FILES['record']['name']){
			$upload = new \Think\Upload();
			$upload->maxSize   =     20971520;
			$upload->exts      =     array('ogg', 'm4a');
			$upload->rootPath  =      './Public/media/';
			$upload->savePath  =      '';
			$info   =   $upload->uploadOne($_FILES['record']);
			if(!$info) {
				$this->error($upload->getError());
			}else{
				$data['record'] = 'media/'.$info['savepath'].$info['savename'];
			}
		}
		
		if($wdb->add($data)){
			$this->success('Added!');
		}else{
			$this->error('Failed!');
		}
		
	}

	public function newW2(){
		$wdb = M('writing');
		$data['article'] = I('question');
		$data['q'] = 1;
		
		if($wdb->add($data)){
			$this->success('Added!');
		}else{
			$this->error('Failed!');
		}
		
	}

	public function newSI(){
		$wdb = M('speaking');
		$data['question'] = I('article');
		$data['q'] = I('q');
		$data['source'] = I('source');
		
		if($wdb->add($data)){
			$this->success('Added!');
		}else{
			$this->error('Failed!');
		}
		
	}
	public function newS3(){
		$wdb = M('speaking');
		$data['article'] = I('article');
		$data['question'] = I('question');
		$data['q'] = I('q');
		$data['source'] = I('source');
		if ($_FILES['record']['name']){
			$upload = new \Think\Upload();
			$upload->maxSize   =     20971520;
			$upload->exts      =     array('ogg', 'm4a');
			$upload->rootPath  =      './Public/media/';
			$upload->savePath  =      '';
			$info   =   $upload->uploadOne($_FILES['record']);
			if(!$info) {
				$this->error($upload->getError());
			}else{
				$data['audio'] = 'media/'.$info['savepath'].$info['savename'];
			}
		}
		
		if($wdb->add($data)){
			$this->success('Added!');
		}else{
			$this->error('Failed!');
		}
		
	}
	public function newS5(){
		$wdb = M('speaking');
		$data['question'] = I('question');
		$data['q'] = I('q');
		$data['source'] = I('source');
		if ($_FILES['record']['name']){
			$upload = new \Think\Upload();
			$upload->maxSize   =     20971520;
			$upload->exts      =     array('ogg', 'm4a');
			$upload->rootPath  =      './Public/media/';
			$upload->savePath  =      '';
			$info   =   $upload->uploadOne($_FILES['record']);
			if(!$info) {
				$this->error($upload->getError());
			}else{
				$data['audio'] = 'media/'.$info['savepath'].$info['savename'];
			}
		}
		
		if($wdb->add($data)){
			$this->success('Added!');
		}else{
			$this->error('Failed!');
		}
		
	}
}
?>